<template>
  <div>
    <!--面包屑导航-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>用户界面</el-breadcrumb-item>
      <el-breadcrumb-item>订单细则</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <!--搜索区域-->
      <el-row :gutter="20">
          <el-button type="primary" @click="addDialog = true">添加细则</el-button>
      </el-row>

      <el-table :data="iventorydata" border stripe class="table-box1">
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单细则号" prop="Dcode"></el-table-column>
        <el-table-column label="订单号" prop="Onumber"></el-table-column>
        <el-table-column label="工厂代码" prop="Fcode"></el-table-column>
        <el-table-column label="商品编号代码" prop="Icode"></el-table-column>
        <el-table-column label="商品数量" prop="Dnumber"></el-table-column>
        <el-table-column label="总金额" prop="Dmoney"></el-table-column>
        <el-table-column label="操作" prop="">
          <template>
            <el-tooltip effect="dark" content="修改" placement="top">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="showmod"
              ></el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="删除" placement="top">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                @click="showdel"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog
      title="添加细则"
      :visible.sync="addDialog"
      width="50%"
      @close="Tclose"
    >
      <!--内容主体区域-->
      <el-form
        :model="addForm"
        :rules="addFormrules"
        ref="addFormRef"
        label-width="150px"
      >
        <el-form-item label="订单细则号" prop="Acode">
          <el-input v-model="addForm.Acode"></el-input>
        </el-form-item>
        <el-form-item label="订单号" prop="Anumber">
          <el-input v-model="addForm.Anumber"></el-input>
        </el-form-item>
        <el-form-item label="工厂代码" prop="Afcode">
          <el-input v-model="addForm.Afcode"></el-input>
        </el-form-item>
        <el-form-item label="商品分类编号" prop="Aicode">
          <el-input v-model="addForm.Aicode"></el-input>
        </el-form-item>
      </el-form>
      <!--底部区域-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialog = false">取 消</el-button>
        <el-button type="primary" @click="addorder">确 定</el-button>
      </span>
    </el-dialog>

    
    
    <el-dialog
      title="删除订单"
      :visible.sync="delDialog"
      width="50%"
      @close="Dclose"
    >
      <!--内容主体区域-->
      <el-form
        :model="delForm"
        :rules="delFormrules"
        ref="delFormRef"
        label-width="150px"
      >
        <el-form-item label="订单细则号" prop="Dcode">
          <el-input v-model="delForm.Dcode"></el-input>
        </el-form-item>
      </el-form>
      <!--底部区域-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="delDialog = false">取 消</el-button>
        <el-button type="primary" @click="delorder">确 定</el-button>
      </span>
    </el-dialog>




    <el-dialog
      title="修改订单细则"
      :visible.sync="editDialogVisible"
      width="50%"
      @close="Eclose"
    >
      <!--内容主体区域-->
      <el-form
        :model="editForm"
        :rules="editFormrules"
        ref="editFormRef"
        label-width="150px"
      >
        <el-form-item label="要修改的订单细则" prop="Ucode">
          <el-input v-model="editForm.Ucode"></el-input>
        </el-form-item>
        <el-form-item label="输入订单号" prop="Unumber">
          <el-input v-model="editForm.Unumber"></el-input>
        </el-form-item>
        <el-form-item label="输入工厂代码" prop="Ufcode">
          <el-input v-model="editForm.Ufcode"></el-input>
        </el-form-item>
        <el-form-item label="输入商品分类编号" prop="Uicode">
          <el-input v-model="editForm.Uicode"></el-input>
        </el-form-item>
        <el-form-item label="输入数量" prop="Udnumber">
          <el-input v-model="editForm.Udnumber"></el-input>
        </el-form-item>
        <el-form-item label="输入总金额" prop="Udmoney">
          <el-input v-model="editForm.Udmoney"></el-input>
        </el-form-item>
      </el-form>
      <!--底部区域-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editorder">确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      query: "",
      iventorydata: [],
      addDialog: false,
      //添加订单细则所用的数据
      addForm: {
        Acode: "",
        Anumber: "",
        Afcode: "",
        Aicode:'',
      },
      addFormrules: {
        Acode: [
          {
            required: true,
            message: "请输入订单细则号",
            trigger: "blur",
          },
        ],
        Anumber: [
          {
            required: true,
            message: "请输入订单号",
            trigger: "blur",
          },
        ],
        Afcode: [
          {
            required: true,
            message: "请输入工厂代码",
            trigger: "blur",
          },
        ],
        Aicode: [
          {
            required: true,
            message: "请输入商品分类编号",
            trigger: "blur",
          },
        ],
      },
      //修改框显示
      editDialogVisible: false,

      //修改所需属性
      editForm: {
        Ucode: "",
        Unumber: "",
        Ufcode: "",
        Uicode: "",
        Udnumber: "",
        Udmoney: "",
      },

      editFormrules: {
        Ucode: [
          {
            required: true,
            message: "请输入订单细则号",
            trigger: "blur",
          },
        ],
        Unumber: [
          {
            required: true,
            message: "请输入订单号",
            trigger: "blur",
          },
        ],
        Ufcode: [
          {
            required: true,
            message: "请输入工厂代码",
            trigger: "blur",
          },
        ],
        Uicode: [
          {
            required: true,
            message: "请输入商品分类编号",
            trigger: "blur",
          },
        ],
      },


      //
      delDialog: false,

      delForm:{
          Dcode: "",
      },

      delFormrules: {
        Dcode: [
          {
            required: true,
            message: "请输入订单细则号",
            trigger: "blur",
          },
        ],
      },

    };
  },
  created() {
    this.geto_messagedata();
  },
  methods: {
    async geto_messagedata() {
      const { data: res } = await this.$http.post("Data/apis/o_detailget", {
        params: this.query,
      });
      this.iventorydata = res;
      console.log(res);
    },

    Tclose() {
      this.$refs.addFormRef.resetFields();
    },

    addorder() {
      this.$refs.addFormRef.validate(async (valid) => {
        if (!valid) return;

        const { data: vsn } = await this.$http.post(
          "Data/apis/o_detailadd",
          this.addForm
        );

        if (vsn.code == 200) {
          this.$message.success("添加成功");
          this.addDialog = false;
          this.geto_messagedata();
        }
      });
    },

    showmod() {
      this.editDialogVisible = true;
    },

    Eclose() {
      this.$refs.editFormRef.resetFields();
    },

    editorder() {
      this.$refs.editFormRef.validate(async (valid) => {
        if (!valid) return;

        const { data: psn } = await this.$http.post(
          "Data/apis/o_detailput",
          this.editForm
        );

        if (psn.code == 200) {
          this.$message.success("修改成功");
          this.editDialogVisible = false;
          this.geto_messagedata();
        }
      });
    },

    Dclose() {
      this.$refs.delFormRef.resetFields();
    },

    showdel() {
        this.delDialog = true;
    },

    delorder() {
        this.$refs.delFormRef.validate(async (valid) => {
        if (!valid) return;

        const { data: gsn } = await this.$http.post(
          "Data/apis/o_detaildel",
          this.delForm
        );

        if (gsn.code == 200) {
          this.$message.success("删除成功");
          this.delDialog = false;
          this.geto_messagedata();
        }
      });
    }

  },
};
</script>

<style>
.table-box1 {
  margin-top: 15px;
  font-size: 12px;
}
</style>